package com.example.classroomPractice0529;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.widget.TextView;

import com.example.yml.R;
import com.example.yml0528.LoginActivity;
import com.example.yml0528.MainActivity;
import com.example.yml0528.RegistActivity;

import java.util.Random;

public class Main3Activity extends AppCompatActivity {
    TextView tv;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            int arg1 = msg.arg1;
            if(arg1==0){
            startActivityForResult(new Intent(Main3Activity.this, com.example.classroomPractice0529.Handler.class), 111);
            finish();
            }
            tv.setText(arg1+"秒后跳转");


        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        tv=findViewById(R.id.tv);
        Random random = new Random();
        random.nextInt(100);
        new Thread() {
           @Override
           public void run() {
               for (int i = 5; i >= 0; i--) {
                   SystemClock.sleep(1000);
                   Message message = new Message();
                   message.arg1=i;
                   handler.sendMessage(message);
               }



//               //获取消息对象
//               Message message = new Message();
//               //把数据放入到消息对象中
//               message.obj = intent;
//               //将消息对象发送到主线程
//               handler.sendMessage(message);
//               //sendMessage()一旦被执行，就会立即激活handleMessage();

           }
       }.start();

    }
}
